import http from '../utils/http'

// 用户管理相关 API（不含环境/资源）

export const createUser = (user) => http.post('/api/users', user)

export const getAllUsers = () => http.get('/api/users')

export const getUserById = (userId) => http.get(`/api/users/${encodeURIComponent(userId)}`)

export const updateUser = (userId, user) => http.put(`/api/users/${encodeURIComponent(userId)}`, user)

export const deleteUser = (userId) => http.delete(`/api/users/${encodeURIComponent(userId)}`)

// 密码、备份与恢复
export const resetUserPassword = (userId, newPassword) =>
	http.post(`/api/users/${encodeURIComponent(userId)}/password/reset`, { newPassword })

export const backupUserData = (userId) =>
	http.post(`/api/users/${encodeURIComponent(userId)}/backup`)

export const restoreUserData = (userId, backupPath) =>
	http.post(`/api/users/${encodeURIComponent(userId)}/restore`, { backupPath })

// 统计&修复
export const getUserStats = () => http.get('/api/users/stats')

export const fixUserPermissions = (userId) =>
	http.post(`/api/users/${encodeURIComponent(userId)}/fix-permissions`)

// 学生分页
export const pageStudents = (params) => http.get('/api/users/students/page', { params })

// 学生专业/班级下拉
export const listStudentMajors = (like) => http.get('/api/users/students/majors', { params: { like } })
export const listStudentClasses = (params) => http.get('/api/users/students/classes', { params })

// 随机用户
export const createRandomUser = (role = 'student') =>
	http.post('/api/users/random', null, { params: { role } })

export const createRandomUsersBatch = (count = 1, role = 'student') =>
	http.post('/api/users/random/batch', null, { params: { count, role } })

